package main

import (
	"fmt"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/data/validation"
	"fyne.io/fyne/v2/widget"
	"github.com/zhaocy/fyne-theme"
)

func main() {
	myApp := app.New()
	myApp.Settings().SetTheme(themex.Themex())
	myWin := myApp.NewWindow("表单")

	//create myform
	myform := widget.NewForm()
	idEntry := widget.NewEntry()
	idEntry.PlaceHolder = "身份证号"
	idEntry.Validator = validation.NewRegexp(`^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)`, "身份证格式错误")

	myform.AppendItem(widget.NewFormItem("身份证", idEntry))

	//设置hint
	myform.Items[0].HintText = "请输入18位身份证号码,不足用X代替"

	myform.OnSubmit = func() {
		if err := myform.Validate(); err != nil {
			fmt.Println(err)
			return
		}
	}

	myWin.SetContent(myform)
	myWin.Resize(fyne.NewSize(550, 450))
	myWin.ShowAndRun()
}
